package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.dto.OrderDTO;
import com.itheima.pojo.Order;
import com.itheima.service.OrderService;
import com.itheima.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    /**
     * 根据id查询预约信息
     * @param id
     * @return
     */
    @PostMapping("/findById")
    public Result findById(Integer id){
        OrderVO orderVO = orderService.findById(id);
        return new Result(true, MessageConstant.QUERY_ORDER_SUCCESS,orderVO);
    }

    /**
     * 提交预约
     *
     * @param orderDTO
     * @return
     */
    @PostMapping("/submitOrder")
    public Result submitOrder(@RequestBody OrderDTO orderDTO){
        Integer id = orderService.submitOrder(orderDTO);

        if(id == 0){
            return new Result(false,MessageConstant.ORDER_FULL);
        }else if (id == -1){
            return new Result(false,MessageConstant.VALIDATECODE_ERROR);
        }else {
            return new Result(true,MessageConstant.ORDER_SUCCESS,id);
        }

    }
}
